package o;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import huawei.android.widget.DecouplingUtil.ReflectUtil;
import java.util.HashMap;
import o.fqk.c;

public class fpt extends ListView {
    private int ʻ;
    private int ʼ;
    private Rect ʽ;
    private iy ˊ;
    private int ˊॱ;
    private boolean ˋ;
    private HashMap<Integer, Drawable> ˋॱ;
    private a ˎ;
    private boolean ˏ;
    private Context ˏॱ;
    private int ͺ;
    private boolean ॱ;
    private int ॱˊ;
    private boolean ॱॱ;
    private int ᐝ;

    class a implements Runnable {
        final /* synthetic */ fpt ˋ;

        private a(fpt o_fpt) {
            this.ˋ = o_fpt;
        }

        public void run() {
            this.ˋ.ˎ = null;
            this.ˋ.drawableStateChanged();
        }

        public void ˏ() {
            this.ˋ.ˎ = null;
            this.ˋ.removeCallbacks(this);
        }

        public void ˎ() {
            this.ˋ.post(this);
        }
    }

    public fpt(@NonNull Context context, boolean z) {
        this(context, z, 16842861);
    }

    public fpt(@NonNull Context context, boolean z, int i) {
        super(context, null, i);
        this.ˏ = false;
        this.ˋ = false;
        this.ॱ = false;
        this.ᐝ = 0;
        this.ʻ = 0;
        this.ʼ = 0;
        this.ʽ = new Rect();
        this.ॱˊ = 0;
        this.ͺ = 0;
        this.ˋॱ = new HashMap(4);
        this.ˋ = z;
        this.ˏॱ = context;
        setCacheColorHint(0);
    }

    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
    }

    protected void layoutChildren() {
        super.layoutChildren();
    }

    protected void dispatchDraw(Canvas canvas) {
        ˎ(canvas);
        super.dispatchDraw(canvas);
    }

    private void ˎ(Canvas canvas) {
        int childCount = getChildCount();
        int checkedItemPosition = getCheckedItemPosition();
        Rect rect = this.ʽ;
        this.ॱˊ = 0;
        this.ͺ = getHeight();
        for (int i = 0; i < childCount; i++) {
            if (checkedItemPosition == getFirstVisiblePosition() + i) {
                View childAt = getChildAt(i);
                Drawable ॱ = ॱ(checkedItemPosition, childAt);
                if (ॱ != null) {
                    int top = childAt.getTop() >= this.ॱˊ ? childAt.getTop() : this.ॱˊ;
                    int bottom = childAt.getBottom() <= this.ͺ ? childAt.getBottom() : this.ͺ;
                    if (getScrollY() > 0 && childAt.getTop() - getScrollY() < this.ॱˊ) {
                        top = getScrollY() + this.ॱˊ;
                    }
                    if (getScrollY() < 0 && childAt.getBottom() - getScrollY() > this.ͺ) {
                        bottom = getScrollY() + this.ͺ;
                    }
                    rect.top = top;
                    rect.bottom = bottom;
                    rect.left = 0;
                    rect.right = getWidth();
                    ॱ.setBounds(rect);
                    ॱ.draw(canvas);
                    rect.setEmpty();
                }
            }
        }
    }

    private Drawable ॱ(int i, View view) {
        if (getChildCount() == 1) {
            return (Drawable) this.ˋॱ.get(Integer.valueOf(0));
        }
        if (i == getFirstVisiblePosition()) {
            return (Drawable) this.ˋॱ.get(Integer.valueOf(1));
        }
        if (i == getLastVisiblePosition()) {
            return (Drawable) this.ˋॱ.get(Integer.valueOf(3));
        }
        if (getScrollY() > 0 && view.getTop() - getScrollY() < this.ॱˊ) {
            return (Drawable) this.ˋॱ.get(Integer.valueOf(1));
        }
        if (getScrollY() >= 0 || view.getBottom() - getScrollY() <= this.ͺ) {
            return (Drawable) this.ˋॱ.get(Integer.valueOf(2));
        }
        return (Drawable) this.ˋॱ.get(Integer.valueOf(3));
    }

    public void setTint(@ColorInt int i) {
        if (i != 0) {
            this.ˊॱ = i;
        } else {
            this.ˊॱ = fo.ˋ(this.ˏॱ, c.ॱ);
        }
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (this.ˎ != null) {
            this.ˎ.ˏ();
        }
        return super.onTouchEvent(motionEvent);
    }

    public boolean onHoverEvent(@NonNull MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 10 && this.ˎ == null) {
            this.ˎ = new a();
            this.ˎ.ˎ();
        }
        boolean onHoverEvent = super.onHoverEvent(motionEvent);
        Object object;
        Class[] clsArr;
        Object[] objArr;
        if (actionMasked == 9 || actionMasked == 7) {
            int pointToPosition = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
            object = ReflectUtil.getObject(this, "mSelectedPosition", ListView.class);
            if (object != null) {
                this.ᐝ = ((Integer) object).intValue();
            }
            if (!(pointToPosition == -1 || pointToPosition == this.ᐝ)) {
                if (getChildAt(pointToPosition - getFirstVisiblePosition()).isEnabled()) {
                    requestFocus();
                    ReflectUtil.callMethod(this, "positionSelector", new Class[]{Integer.TYPE, View.class}, new Object[]{Integer.valueOf(pointToPosition), r0}, ListView.class);
                    clsArr = new Class[]{Integer.TYPE};
                    objArr = new Object[]{Integer.valueOf(pointToPosition)};
                    ReflectUtil.callMethod(this, "setSelectedPositionInt", clsArr, objArr, ListView.class);
                    ReflectUtil.callMethod(this, "setNextSelectedPositionInt", clsArr, objArr, ListView.class);
                }
                ReflectUtil.callMethod(this, "updateSelectorState", null, null, ListView.class);
            }
        } else {
            boolean booleanValue;
            object = ReflectUtil.callMethod(this, "shouldShowSelector", null, null, ListView.class);
            if (object != null) {
                booleanValue = ((Boolean) object).booleanValue();
            } else {
                booleanValue = true;
            }
            if (!booleanValue) {
                clsArr = new Class[]{Integer.TYPE};
                objArr = new Object[]{Integer.valueOf(-1)};
                ReflectUtil.callMethod(this, "setSelectedPositionInt", clsArr, objArr, ListView.class);
                ReflectUtil.callMethod(this, "setNextSelectedPositionInt", clsArr, objArr, ListView.class);
            }
        }
        return onHoverEvent;
    }

    protected void drawableStateChanged() {
        if (this.ˎ == null) {
            super.drawableStateChanged();
        }
    }

    public boolean ˏ(@NonNull MotionEvent motionEvent, int i) {
        boolean z;
        boolean z2;
        int actionMasked = motionEvent.getActionMasked();
        switch (actionMasked) {
            case 1:
                z = false;
                break;
            case 2:
                z = true;
                break;
            case 3:
                z = false;
                z2 = false;
                break;
            default:
                z = false;
                z2 = true;
                break;
        }
        int findPointerIndex = motionEvent.findPointerIndex(i);
        if (findPointerIndex < 0) {
            z = false;
            z2 = false;
        } else {
            int x = (int) motionEvent.getX(findPointerIndex);
            findPointerIndex = (int) motionEvent.getY(findPointerIndex);
            int pointToPosition = pointToPosition(x, findPointerIndex);
            if (pointToPosition == -1) {
                z2 = z;
                z = true;
            } else {
                View childAt = getChildAt(pointToPosition - getFirstVisiblePosition());
                ˏ(childAt, pointToPosition, (float) x, (float) findPointerIndex);
                if (actionMasked == 1) {
                    performItemClick(childAt, pointToPosition, getItemIdAtPosition(pointToPosition));
                    z = false;
                    z2 = true;
                }
                z = false;
                z2 = true;
            }
        }
        if (!z2 || r0) {
            ॱ();
        }
        if (z2) {
            if (this.ˊ == null) {
                this.ˊ = new iy(this);
            }
            this.ˊ.ˏ(true);
            this.ˊ.onTouch(this, motionEvent);
        }
        if (this.ˊ != null) {
            this.ˊ.ˏ(false);
        }
        return z2;
    }

    public void setListSelectionHidden(boolean z) {
        this.ˏ = z;
    }

    private void ॱ() {
        this.ॱ = false;
        setPressed(false);
        ReflectUtil.callMethod(this, "updateSelectorState", null, null, ListView.class);
        Object object = ReflectUtil.getObject(this, "mMotionPosition", ListView.class);
        if (object != null) {
            this.ʻ = ((Integer) object).intValue();
        }
        object = ReflectUtil.getObject(this, "mFirstPosition", ListView.class);
        if (object != null) {
            this.ʼ = ((Integer) object).intValue();
        }
        View childAt = getChildAt(this.ʻ - this.ʼ);
        if (childAt != null) {
            childAt.setPressed(false);
        }
    }

    private void ˏ(@NonNull View view, int i, float f, float f2) {
        this.ॱ = true;
        if (VERSION.SDK_INT >= 21) {
            drawableHotspotChanged(f, f2);
        }
        if (!isPressed()) {
            setPressed(true);
        }
        Object object = ReflectUtil.getObject(this, "mDataChanged", ListView.class);
        if (object != null) {
            this.ॱॱ = ((Boolean) object).booleanValue();
        }
        if (this.ॱॱ) {
            layoutChildren();
        }
        object = ReflectUtil.getObject(this, "mMotionPosition", ListView.class);
        if (object != null) {
            this.ʻ = ((Integer) object).intValue();
        }
        object = ReflectUtil.getObject(this, "mFirstPosition", ListView.class);
        if (object != null) {
            this.ʼ = ((Integer) object).intValue();
        }
        View childAt = getChildAt(this.ʻ - this.ʼ);
        boolean z = (childAt == null || childAt == view || !childAt.isPressed()) ? false : true;
        if (z) {
            childAt.setPressed(false);
        }
        this.ʻ = i;
        float left = f - ((float) view.getLeft());
        float top = f2 - ((float) view.getTop());
        if (VERSION.SDK_INT >= 21) {
            view.drawableHotspotChanged(left, top);
        }
        if (!view.isPressed()) {
            view.setPressed(true);
        }
        ReflectUtil.callMethod(this, "setSelectedPositionInt", new Class[]{Integer.TYPE}, new Object[]{Integer.valueOf(i)}, ListView.class);
        ReflectUtil.callMethod(this, "positionSelectorLikeTouch", new Class[]{Integer.TYPE, View.class, Float.TYPE, Float.TYPE}, new Object[]{Integer.valueOf(i), view, Float.valueOf(f), Float.valueOf(f2)}, ListView.class);
        refreshDrawableState();
    }

    public boolean isInTouchMode() {
        return (this.ˋ && this.ˏ) || super.isInTouchMode();
    }

    public boolean hasWindowFocus() {
        return this.ˋ || super.hasWindowFocus();
    }

    public boolean isFocused() {
        return this.ˋ || super.isFocused();
    }

    public boolean hasFocus() {
        return this.ˋ || super.hasFocus();
    }

    public void setSelectorDrawables(HashMap<Integer, Drawable> hashMap) {
        if (hashMap != null) {
            this.ˋॱ = hashMap;
        }
    }
}
